package com.snail.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.snail.model.pojo.cart.BizRefundRequest;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface MerchantRefundOrderMapper extends BaseMapper<BizRefundRequest> {

    /**
     * 根据退款单号查询
     * @param refundNo 退款单号
     * @return 退款单信息
     */

    BizRefundRequest selectByRefundNo(@Param("refundNo") String refundNo);

    // 多条件分页查询商家的所有退款申请（按创建时间倒序）
    IPage<BizRefundRequest> selectMerchantRefunds(Page<BizRefundRequest> page, @Param("refundRequest") BizRefundRequest refundRequest);

    //新增退款单在商家端

    @Insert("insert into biz_refund_requests (order_id, user_id, refund_no, payment_id, refund_amount, reason, status, create_time) " +
            "values (#{orderId}, #{userId}, #{refundNo}, #{paymentId}, #{refundAmount}, #{reason}, #{status}, #{createTime})")
    void insertRefund(BizRefundRequest refundRequest);

    //处理退款申请，同意或拒绝，拒绝原因，同步到用户端
    @Update("update biz_refund_requests set status = #{status}, reject_reason = #{rejectReason}, processed_at = #{processedAt}, update_time = #{updateTime} where refund_no = #{refundNo}")
    void updateRefund(BizRefundRequest refundRequest);


}
